<!--
 * @Description: 
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-08-29 18:31:54
 * @LastEditors: ziwei
 * @LastEditTime: 2021-09-26 17:59:08
-->
<template>
  <div>
    计数器：{{ count }}{{$store.state.count}}
    <hr />
    double:{{ double }}{{$store.getters.double}}
    <button @click="$store.state.count++">错误修改</button>
    <button @click="add">同步修改</button>
    <button @click="asyncAdd">异步修改</button>
    <!-- <img alt="Vue logo" src="./assets/logo.png" />
    <HelloWorld msg="Welcome to Your Vue.js App" /> -->
    <hr>
    a模块：{{aCount}}{{bCount}}{{cCount}}
    <button @click="$store.commit('aCount/add',1)">改a</button>
    <button @click="$store.commit('bCount/add',1)">改b</button>
  </div>
</template>

<script>
import { computed } from "vue";
import HelloWorld from "./components/HelloWorld.vue";
import { useStore } from "@/vuex";

function useCount() {
  const store = useStore();
  function add() {
    store.commit("add", 1);
  }
  function asyncAdd() {
    store.dispatch("asyncAdd", 1);
  }
}

export default {
  name: "App",
  setup() {
    const store = useStore();
    console.log("storestore",store);

    function add() {
      store.commit('add',1);
    }

    function asyncAdd() {
      store.dispatch('asyncAdd',1);
    }
    //let methods = useCount();
    return {
      count: computed(() => store.state.count),
      double: computed(() => store.getters.double),
      aCount:computed(()=>{
        return store.state.aCount.count
        }),
      bCount:computed(()=>{return store.state.bCount.count}),
      cCount:computed(()=>{return store.state.aCount.cCount.count}),
      add,
      asyncAdd,
      //...methods,
    };
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
